*******REPLICATION APPENDIX****

* CHANGE THIS

cd /path/to/directory

clear

use "data_YLE_main.dta"

replace Refugeespercapita = 0 if year < 2017

gen percent_pop_arrivals = Refugeespercapita * 100

label def refugees 1 "Strongly agree" 2 "Somewhat agree" 3 "Somewhat disagree" 4 "Strongly disagree"

label val refugees refugees

**first reversing the scale**

vreverse refugees, gen(ref_2) 

*******************************************************************************

*** Figure D1:  interactions with kernel regression 
* Note that these take about 15 minutes to run each

* a) POPULATION

gen log_pop = log(population)

* LONG TIME
interflex ref_2 treat log_pop if Pretreated==0 ///
    , type(kernel)  xd(density) fe(CandidateID year) cl(municode) yr(-1 1)

* b) URBAN DENSITY

gen logurban = log(urban)

* note that the 84 observations with 0 urban density will go missing: this does not affect the results

* LONG TIME
interflex ref_2 treat logurban if Pretreated==0 ///
    , type(kernel)  xd(density) fe(CandidateID year) cl(municode) yr(-1 1)

*******************************************************************************

*** Figure D2:  further demographic interactions

* a) log of residents under 15

gen log15 =  log(under_15)

interflex ref_2 treat log15 if Pretreated==0 ///
    , vce(r) xd(density) fe(CandidateID year) cl(municode) yr(-1 1)

* b) log of dependency ratio

gen logdep = log(dependency_ratio)

interflex ref_2 treat logdep if Pretreated==0 ///
    , vce(r) xd(density) fe(CandidateID year) cl(municode) yr(-1 1)

*******************************************************************************

*** Figure D3:  Municipality debt interaction

destring munidebt, replace

interflex ref_2 treat munidebt if Pretreated==0 ///
    , vce(r) xd(density) fe(CandidateID year) cl(municode) yr(-1 1)

*******************************************************************************

*** Table D1

xtset CandidateID year
xtreg ref_2 treat i.year if (Pretreated==0 & urban < 40 & population < 15000), fe cl(municode)

xtreg ref_2 treat i.year if (Pretreated==0 & urban >= 70 & population < 15000), fe cl(municode)

* to get the n

tab firstdiff if (Pretreated == 0 & urban < 40 & population < 15000)
tab firstdiff if (Pretreated == 0 & urban >= 70 & population < 15000)

*******************************************************************************

*** Table D2:  interactions with time

gen logdays = log(duration_days)

replace logdays = 0 if missing(logdays)

replace percent_pop_arrivals = 0 if year == 2012
replace logdays = 0 if year == 2012

xtreg ref_2 c.percent_pop_arrivals##c.logdays i.year if Pretreated==0, fe cluster(municode)

xtreg ref_2 c.percent_pop_arrivals##c.logdays i.year urban foreigners changeinpop swedish highereduc ///
    if Pretreated==0, fe cluster(municode)

*******************************************************************************

*** Table E1:  compositional effects

* model 1

xtset municode
xtreg ref_2 percent_pop_arrivals i.year if Pretreated == 0, fe cluster(municode)

* model 3
xtset CandidateID year
xtreg ref_2 percent_pop_arrival i.year if Pretreated==0, fe cl(municode)

* n = 

tab ref_2 if (!missing(firstdiff) & Pretreated == 0)

* model 2: need to drop firstdifferences: this indicates that the candidate did not run twice

drop if !missing(firstdiff)

* Keeping only those who did not answer the qestion in both time points

xtset municode
xtreg ref_2 percent_pop_arrivals i.year if Pretreated == 0, fe cluster(municode)

* back to using the previous data

clear

use "data_YLE_main.dta"

gen percent_pop_arrivals = Refugeespercapita * 100

label def refugees 1 "Strongly agree" 2 "Somewhat agree" 3 "Somewhat disagree" 4 "Strongly disagree"

label val refugees refugees

replace percent_pop_arrivals = 0 if year==2012

* first reversing the scale

vreverse refugees, gen(ref_2)

*******************************************************************************

*** Table E2

* Party level sub-group analysis

* SDP, Socialist

xtset CandidateID year

xtreg ref_2 percent_pop_arrivals i.year if party == 1 & Pretreated==0, fe cluster(municode) 

* KOK, Lib. right

xtreg ref_2 percent_pop_arrivals i.year if party == 2 & Pretreated==0, fe cluster(municode) 

* KESK Agr Center

xtreg ref_2 percent_pop_arrivals i.year if party == 3 & Pretreated==0, fe cluster(municode) 

* PS True Finns

xtreg ref_2 percent_pop_arrivals i.year if party == 10 & Pretreated==0, fe cluster(municode)

* VAS Left

xtreg ref_2 percent_pop_arrivals i.year if party == 4 & Pretreated==0, fe cluster(municode) 

* GREENS VIHR

xtreg ref_2 percent_pop_arrivals i.year if party == 5 & Pretreated==0, fe cluster(municode) 

* Christian Democrats KD

xtreg ref_2 percent_pop_arrivals i.year if party == 7 & Pretreated==0, fe cluster(municode)

* Swedish People's Party, SFP

xtreg ref_2 percent_pop_arrivals i.year if party == 6 & Pretreated==0, fe cluster(municode)

*******************************************************************************

*** TABLE E3:  Winning candidates

* make the count for  N

tab ref_2 if elected ==1 & Pretreated==0
* 9,928

* basic model

xtset municode
xtreg ref_2 percent_pop_arrivals i.year if elected==1 & Pretreated==0, fe cl(municode)

* with covariates

xtset municode
xtreg ref_2 percent_pop_arrivals urban changeinpop swedish highereduc foreigners i.year if elected==1 & Pretreated==0, fe cl(municode)

*******************************************************************************

*** Figure E1: Interactions for winners

* a) population

gen logpop = log(population)

interflex ref_2 treat logpop if Pretreated==0 & elected==1, vce(r) xd(density) fe(municode year) cl(municode) yr(-1 1)

* b) density

gen logdensity = log(urban)
 
interflex ref_2 treat logdensity if Pretreated==0 & elected==1, vce(r) xd(density) fe(municode year) cl(municode) yr(-1 1)

* c) taxrevenue

interflex ref_2 treat taxrevenue if Pretreated==0 & elected==1, vce(r) xd(density) fe(municode year) cl(municode) yr(-1 1)

* d) population changeinpop

interflex ref_2 treat changeinpop if Pretreated==0 & elected==1, vce(r) xd(density) fe(municode year) cl(municode) yr(-1 1)

* e) log of under 15

gen log15 = log(under_15)

interflex ref_2 treat log15 if Pretreated==0 & elected==1, vce(r) xd(density) fe(municode year) cl(municode) yr(-1 1)

* f) logged dependency ratio

gen logdep = log(dependency_ratio)

interflex ref_2 treat logdep if Pretreated==0 & elected==1, vce(r) xd(density) fe(municode year) cl(municode) yr(-1 1)

*******************************************************************************

*** Table E4

clear

use "data_src_muni_economics.dta"

* pre-treated already dropped from this dataset

* Model:  binary treatment

xtset municode year

* Column 1
xtreg Taxincome treat i.year, fe cl(municode)
* Column 2 
xtreg contribution_margin treat i.year, fe cl(municode)
* Column 3
xtreg service  treat i.year, fe cl(municode)
* Column 4
xtreg unemployed treat i.year, fe cl(municode)

* Model:  continous treatment

xtset municode year

* Column 1
xtreg Taxincome refugee_percent i.year, fe cl(municode)
* Column 2 
xtreg contribution_margin refugee_percent i.year, fe cl(municode)
* Column 3
xtreg service  refugee_percent i.year, fe cl(municode)
* Column 4
xtreg unemployed refugee_percent i.year, fe cl(municode)

* Model:  interaction term:  time x intensity

* Column 1
xtreg Taxincome c.logduration##c.refugee_percent i.year, fe cl(municode)
* Column 2 
xtreg contribution_margin c.logduration##c.refugee_percent i.year, fe cl(municode)
* Column 3
xtreg service  c.logduration##c.refugee_percent i.year, fe cl(municode)
* Column 4
xtreg unemployed c.logduration##c.refugee_percent i.year, fe cl(municode)

*******************************************************************************

*** Table F1:  incumbency effect

clear

use "data_YLE_main.dta"

replace Refugeespercapita = 0 if year < 2017

gen percent_pop_arrivals = Refugeespercapita * 100

vreverse refugees, gen(ref_2)

* model 1 incumbence x treatment

xtset CandidateID year

xtreg ref_2 i.incumbent##c.percent_pop_arrivals i.year if Pretreated==0, fe cluster(municode)

* model 2 just incumbency

xtreg ref_2 incumbent i.year if Pretreated==0, fe cluster(municode)

*******************************************************************************

*** TABLE F2:  Other electoral effects

* Model 1 challenger x treatment interaction**

xtreg ref_2  i.spare##c.percent_pop_arrivals i.year if Pretreated==0 & loser==0, fe cluster(municode)

* Model 2: challenger only***

xtreg ref_2 spare i.year if Pretreated==0, fe cluster(municode)

* Model 3: loser x treatment*

xtreg ref_2 i.loser##c.percent_pop_arrivals i.year if Pretreated==0, fe cluster(municode)

* Model 4: loser only***

xtreg ref_2 loser i.year if Pretreated==0, fe cluster(municode)

*******************************************************************************

*** TABLE F 3:  Public-Private test

xtset CandidateID year

xtreg ref_2 percent_pop_arrivals i.year if private==0 & Pretreated==0, fe cl(municode) 
xtreg ref_2 percent_pop_arrivals i.year if public==0 & Pretreated==0, fe cl(municode) 

*******************************************************************************

***TABLE F4 Jacknifing

* Jackknifing

xtset CandidateID year

* Continuous
* LONG TIME
jackknife, cluster(municode): xtreg ref_2 percent_pop_arrivals  i.year if Pretreated==0, fe

* Continuous with covariates
* LONG TIME
jackknife, cluster(municode): xtreg ref_2 percent_pop_arrivals urban foreigners changeinpop swedish highereduc i.year if Pretreated==0 , fe

*******************************************************************************

*** Table F5:  SUTVA

* Adjecent treat

gen adjacenttreat = 0
replace adjacenttreat = 1 if year==2017 & Adjacent_to_treated==1

xtreg ref_2 treat i.year if population < 15000 & Pretreated==0, fe cl(municode)

* vs. 

xtreg refugees adjacenttreat i.year if population < 15000 & Pretreated==0 & Treated2015==0, fe cl(municode) 

*******************************************************************************

*** Table F6:  Placebo regressions

clear

use "data_src_2008_2012_2017_anonym.dta"

gen treat = 0
replace treat = 1 if Treated2015 == 1 & year > 2015

rename refugees_per_capita Refugeespercapita

replace Refugeespercapita = 0 if year < 2017

gen percent_pop_arrivals = Refugeespercapita * 100

xtset CandidateID year

* model 1

xtreg env_2 treat i.year if Pretreated==0, fe cluster(municode)

* 0.0196713   .0333911     0.59   0.556 

* model 2

xtreg env_2 percent_pop_arrivals i.year if Pretreated==0, fe cluster(municode)

* 0.0142259   .0194127     0.73   0.464  

* to get the N

drop env_2 treat percent_pop_arrivals Refugeespercapita duration_days

reshape wide foreignname votes voteshare age elected privatization carehome environment ///
    refugees Urban dependencyratio agriculture education population changeinpop ///
    under15_ over64_ swedish foreigners birthsurplus popinflow nrofam privatehouses ///
    secondaryeduc highereduc employment unemployment pensioners industry service ///
    contributionmargin taxrevenue ///
    , i(CandidateID) j(year)

tab CandidateID if !missing(environment2008) & !missing(environment2012) & !missing(environment2017) & Pretreated == 0

*******************************************************************************

*** Table F7:  HS replication

clear

use "data_src_HS_anom_shortened.dta"

replace refugees_per_capita = 0 if year < 2017

gen percent_refugee = refugees_per_capita * 100

xtset CandidateID year

* overall
xtreg refugees percent_refugee i.year if Pretreated==0, fe cl(municode)

* per party*

* KOK
xtreg refugees percent_refugee i.year if Party==1 & Pretreated==0, fe cl(municode)

* SDP
xtreg refugees percent_refugee i.year if Party==2 & Pretreated==0, fe cl(municode)

* KESK
xtreg refugees percent_refugee i.year if Party==3 & Pretreated==0, fe cl(municode)

* PS
xtreg refugees percent_refugee i.year if Party==4 & Pretreated==0, fe cl(municode)

* VIHR
xtreg refugees percent_refugee i.year if Party==5 & Pretreated==0, fe cl(municode)

* VAS
xtreg refugees percent_refugee i.year if Party==6 & Pretreated==0, fe cl(municode)

* SFP
xtreg refugees percent_refugee i.year if Party==7 & Pretreated==0, fe cl(municode)

* KD
xtreg refugees percent_refugee i.year if Party==8 & Pretreated==0, fe cl(municode)

